#include <iostream>

#include "iostream"
#include "vector"
#include "unordered_map"
#include "unordered_set"
#include "algorithm"
#include "string"
#include "list"
#include "string.h"


class OneLoop {
public:
//    std::unordered_map<int64_t,char> node_appear;
    std::vector<int> hs;
    std::vector<int> temp;
    std::vector<int> nxss;
    int nxs=0;
    void merge(int begin,int mid,int end){
        int temp_i=0;
        int a_i=begin,b_i=mid+1;
        while (a_i<=mid&&b_i<=end){
            if(hs[a_i]<=hs[b_i]){
                temp[temp_i]=hs[a_i];
                nxss[a_i]+=b_i-mid-1;

                temp_i++;a_i++;
            }else{
                //前面大于后面
                nxss[b_i]+=mid-a_i+1;
                temp[temp_i]=hs[b_i];

                temp_i++;b_i++;
            }
        }
        while (a_i<=mid){
            nxss[a_i]+=end-mid;
            temp[temp_i]=hs[a_i];
            temp_i++;a_i++;
        }
        while (b_i<=end){
                temp[temp_i]=hs[b_i];
                temp_i++;b_i++;
        }
        for(int i=0;i<temp_i;i++){
            hs[begin+i]=temp[i];
        }
    }
    void merge_sort(int begin,int end){
        if(begin==end){
            return;
        }
        int mid=(begin+end)/2;
        merge_sort(begin,mid);
        merge_sort(mid+1,end);
        merge(begin,mid,end);
    }
    int bgxd(int m){
        return (2+m)*(m-1)/2+1;
    }
    bool run(
            int64_t n
//            std::string&s1,std::string& s2
    ) {
        for(int i=0;i<n;i++){
            int h;std::cin>>h;
            hs.push_back(h);
        }
        temp.resize(n);
        nxss.resize(n);
        merge_sort(0,n-1);
        int k=0;
        for(auto s:nxss){
            k+= (s+1)*s/2;
        }
        printf("%d\n",k);
        //nxs*2 交换次数
        //交换次数/n 每个人交换次数(不开心增加次数
        return false;
    }
};

class Solution {
public:
    void run() {

        bool first = true;
        int64_t a, b, c, d, e;
        //        std::cin >> a;
//        std::string s1,s2;
//        while (1){
        while (
//                std::getline(std::cin,s1)
                std::cin >> a
                ) {
//            std::getline(std::cin,s2);
            OneLoop l;
            if (!l.run(a)) {
//                return;
            }
        }


    }
};

int main() {

    //    bool cur_num= true;
    Solution().run();
    return 0;
}

